using System;
using System.Security.Permissions;
using System.Web;

using PickGold.Charting.Data;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeSeriesCollection_SeriesCollection")]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class SeriesCollection : ChartNamedElementCollection<Series>
	{
		internal SeriesCollection(DataManager dataManager) : base(dataManager)
		{
		}

		public Series Add(string name)
		{
			Series item = new Series(name);
			base.Add(item);
			return item;
		}

		internal void ChartAreaNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
		{
			foreach (Series series in this)
			{
				if (series.ChartArea == e.OldName)
				{
					series.ChartArea = e.NewName;
				}
			}
		}

		internal override void FixNameReferences(Series item)
		{
			if ((item != null) && (base.Chart != null))
			{
				if (string.IsNullOrEmpty(item.ChartArea) && (base.Chart.ChartAreas != null))
				{
					item.ChartArea = base.Chart.ChartAreas.DefaultNameReference;
				}
				if (string.IsNullOrEmpty(item.Legend) && (base.Chart.Legends != null))
				{
					item.Legend = base.Chart.Legends.DefaultNameReference;
				}
			}
		}

		internal void LegendNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
		{
			foreach (Series series in this)
			{
				if (series.Legend == e.OldName)
				{
					series.Legend = e.NewName;
				}
			}
		}
	}
}

